home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / lib / calc / regress.cal < prev    next >
Text File  |  1995-07-17  |  22KB  |  736 lines

  1. /*
  2.  * Copyright (c) 1993 David I. Bell
  3.  * Permission is granted to use, distribute, or modify this source,
  4.  * provided that this copyright notice remains intact.
  5.  *
  6.  * Test the correct execution of the calculator by reading this library file.
  7.  * Errors are reported with '****' messages, or worse.  :-)
  8.  *
  9.  * NOTE: Unlike most calc lib files, this one performs its work when
  10.  *       it is read.  Normally one would just define functions and
  11.  *     values for later use.  In the case of the regression test,
  12.  *     we do not want to do this.
  13.  */
  14.  
  15. static err;
  16.  
  17.  
  18. define verify(test, str)
  19. {
  20.     if (test != 1) {
  21.         print '**** Non-true result (' : test : '): ' : str;
  22.         ++err;
  23.         return;
  24.     }
  25.     print str;
  26. }
  27.  
  28.  
  29. define error(str)
  30. {
  31.     print '****' , str;
  32.     ++err;
  33. }
  34.  
  35.  
  36. define getglobalvar()
  37. {
  38.     global    globalvar;
  39.  
  40.     return globalvar;
  41. }
  42.  
  43.  
  44. /*
  45.  * Test boolean operations and IF tests.
  46.  *
  47.  * Some of these tests are done twice, once to print the message and
  48.  * once to count any errors.  This means that some successful tests
  49.  * will display a passing message twice.  Oh well, no biggie.
  50.  */
  51. define test_booleans()
  52. {
  53.     local    x;
  54.     local    y;
  55.     local    t1, t2, t3;
  56.  
  57.     print '100: Beginning test_booleans';
  58.  
  59.     if (0)
  60.         print '**** if (0)';
  61.     if (0)
  62.         err = err + 1;
  63.  
  64.     if (1)
  65.         print '101: if (1)';
  66.  
  67.     if (2)
  68.         print '102: if (2)';
  69.  
  70.     if (1)
  71.         print '103: if (1) else';
  72.     else
  73.         print '**** if (1) else';
  74.     if (1)
  75.         print '104: if (1) else';
  76.     else
  77.         err = err + 1;
  78.  
  79.     if (0)
  80.         print '**** if (0) else';
  81.     else
  82.         print '105: if (0) else';
  83.     if (0)
  84.         err = err + 1;
  85.     else
  86.         print '106: if (0) else';
  87.  
  88.     if (1 == 1)
  89.         print '107: if 1 == 1';
  90.     else
  91.         print '**** if 1 == 1';
  92.     if (1 == 1)
  93.         print '108: if 1 == 1';
  94.     else
  95.         err = err + 1;
  96.  
  97.     if (1 != 2)
  98.         print '109: if 1 != 2';
  99.     else
  100.         print '**** if 1 != 2';
  101.     if (1 != 2)
  102.         print '110: if 1 != 2';
  103.     else
  104.         err = err + 1;
  105.  
  106.     verify(1,      '111: verify 1');
  107.     verify(2 == 2, '112: verify 2 == 2');
  108.     verify(2 != 3, '113: verify 2 != 3');
  109.     verify(2 <  3, '114: verify 2 <  3');
  110.     verify(2 <= 2, '115: verify 2 <= 2');
  111.     verify(2 <= 3, '116: verify 2 <= 3');
  112.     verify(3 >  2, '117: verify 3 >  2');
  113.     verify(2 >= 2, '118: verify 2 >= 2');
  114.     verify(3 >= 2, '119: verify 3 >= 2');
  115.     verify(!0,     '120: verify !0');
  116.     verify(!1 == 0,'121: verify !1 == 0');
  117.     print '122: Ending test_booleans';
  118. }
  119.  
  120.  
  121. /*
  122.  * Test variables and simple assignments.
  123.  */
  124. define test_variables()
  125. {
  126.     local    x1, x2, x3;
  127.     global    g1, g2;
  128.     local    t;
  129.     global    globalvar;
  130.  
  131.     print '200: Beginning test_variables';
  132.     x1 = 5;
  133.     x3 = 7 * 2;
  134.     x2 = 9 + 1;
  135.     globalvar = 22;
  136.     g1 = 19 - 3;
  137.     g2 = 79;
  138.     verify(x1 == 5,  '201: x1 == 5');
  139.     verify(x2 == 10, '202: x2 == 10');
  140.     verify(x3 == 14, '203: x3 == 14');
  141.     verify(g1 == 16, '204: g1 == 16');
  142.     verify(g2 == 79, '205: g2 == 79');
  143.     verify(globalvar == 22, '204: globalvar == 22');
  144.     verify(getglobalvar() == 22, '205: getglobalvar() == 22');
  145.     x1 = x2 + x3 + g1;
  146.     verify(x1 == 40, '206: x1 == 40');
  147.     g1 = x3 + g2;
  148.     verify(g1 == 93, '207: g1 == 207');
  149.     x1 = 5;
  150.     verify(x1++ == 5, '208: x1++ == 5');
  151.     verify(x1 == 6, '209: x1 == 6');
  152.     verify(++x1 == 7, '210: ++x1 == 7');
  153.     x1 += 3;
  154.     verify(x1 == 10, '211: x1 == 10');
  155.     x1 -= 6;
  156.     verify(x1 == 4, '212: x1 == 4');
  157.     x1 *= 3;
  158.     verify(x1 == 12, '213: x1 == 12');
  159.     x1 /= 4;
  160.     verify(x1 == 3, '214: x1 == 3');
  161.     x1 = x2 = x3;
  162.     verify(x2 == 14, '215: x2 == 14');
  163.     verify(x1 == 14, '216: x1 == 14');
  164.     print '217: Ending test_variables';
  165. }
  166.  
  167.  
  168. /*
  169.  * Test logical AND and OR operators and short-circuit evaluation.
  170.  */
  171. define test_logicals()
  172. {
  173.     local    x;
  174.  
  175.     print '300: Beginning test_logicals';
  176.  
  177.     if (2 && 3) {
  178.         print '301: if (2 && 3)';
  179.     } else {
  180.         print '**** if (2 && 3)';
  181.         ++err;
  182.     }
  183.  
  184.     if (2 && 0) {
  185.         print '**** if (2 && 0)';
  186.         ++err;
  187.     } else {
  188.         print '302: if (2 && 0)';
  189.     }
  190.  
  191.     if (0 && 2) {
  192.         print '**** if (0 && 2)';
  193.         ++err;
  194.     } else {
  195.         print '303: if (0 && 2)';
  196.     }
  197.  
  198.     if (0 && 0) {
  199.         print '**** if (0 && 0)';
  200.         ++err;
  201.     } else {
  202.         print '304: if (0 && 0)';
  203.     }
  204.  
  205.     if (2 || 0) {
  206.         print '305: if (2 || 0)';
  207.     } else {
  208.         print '**** if (2 || 0)';
  209.         ++err;
  210.     }
  211.     
  212.     if (0 || 2) {
  213.         print '306: if (0 || 2)';
  214.     } else {
  215.         print '**** if (0 || 2)';
  216.         ++err;
  217.     }
  218.  
  219.     if (0 || 0) {
  220.         print '**** if (0 || 0)';
  221.         ++err;
  222.     } else {
  223.         print '307: if (0 || 0)';
  224.     }
  225.  
  226.     x = 2 || 3; verify(x == 2, '308: (2 || 3) == 2');
  227.     x = 2 || 0; verify(x == 2, '309: (2 || 0) == 2');
  228.     x = 0 || 3; verify(x == 3, '310: (0 || 3) == 3');
  229.     x = 0 || 0; verify(x == 0, '311: (0 || 0) == 0');
  230.     x = 2 && 3; verify(x == 3, '312: (2 && 3) == 3');
  231.     x = 2 && 0; verify(x == 0, '313: (2 && 0) == 0');
  232.     x = 0 && 3; verify(x == 0, '314: (0 && 3) == 0');
  233.     x = 2 || error('2 || error()');
  234.     x = 0 && error('0 && error()');
  235.     print '315: Ending test_logicals';
  236. }
  237.  
  238.  
  239. /*
  240.  * Test simple arithmetic operations and expressions.
  241.  */
  242. define test_arithmetic()
  243. {
  244.     print '400: Beginning test_arithmetic';
  245.     verify(3+4==7, '401: 3 + 4 == 7');
  246.     verify(4-1==3, '402: 4 - 1 == 3');
  247.     verify(2*3==6, '403: 2 * 3 == 6');
  248.     verify(8/4==2, '404: 8 / 4 == 2');
  249.     verify(2^3==8, '405: 2 ^ 3 == 8');
  250.     verify(9-4-2==3, '406: 9-4-2 == 3');
  251.     verify(9-4+2==7, '407: 9-4+2 == 6');
  252.     verify(-5+2==-3,  '408: -5+2 == -3');
  253.     verify(2*3+1==7, '409: 2*3+1 == 7');
  254.     verify(1+2*3==7, '410: 1+2*3 == 7');
  255.     verify((1+2)*3==9, '411: (1+2)*3 == 9');
  256.     verify(2*(3+1)==8, '412: 2*(3+1) == 8');
  257.     verify(9-(2+3)==4, '413: 9-(2+3) == 4');
  258.     verify(9+(2-3)==8, '414: 9+(2-3) == 8');
  259.     verify((2+3)*(4+5)==45, '415: (2+3)*(4+5) == 45');
  260.     verify(10/(2+3)==2, '416: 10/(2+3) == 2');
  261.     verify(12/3+4==8, '417: 12/3+4 == 8');
  262.     verify(6+12/3==10, '418: 6+12/3 == 10');
  263.     verify(2+3==1+4, '419: 2+3 == 1+4');
  264.     verify(-(2+3)==-5, '420: -(2+3) == -5');
  265.     verify(7&18==2,    '421: 7&18 == 2');
  266.     verify(3|17==19,   '422: 3|17 == 19');
  267.     verify(2&3|1==3,   '423: 2&3|1 == 3');
  268.     verify(2&(3|1)==2, '424: 2&(3|1) == 2');
  269.     verify(3<<4==48,   '425: 3<<4 == 48');
  270.     verify(5>>1==2,    '426: 5>>1 == 2');
  271.     verify(3<<-1==1,   '427: 3<<-1 == 1');
  272.     verify(5>>-2==20,  '428: 5>>-2 == 20');
  273.     verify(1<<2<<3==65536, '429: 1<<2<<3 == 65536');
  274.     verify((1<<2)<<3==32, '430: (1<<2)<<3 == 32');
  275.     verify(2^3^2==512, '431: 2^3^2 == 512');
  276.     verify((2^3)^2==64,'432: (2^3)^2 == 64');
  277.     verify(4//3==1, '433: 4//3==1');
  278.     verify(4//-3==-1, '434: 4//-3==-1');
  279.     verify(0.75//-0.51==-1, '435: 0.75//-0.51==-1');
  280.     verify(0.75//-0.50==-1, '436: 0.75//-0.50==-1');
  281.     verify(0.75//-0.49==-1, '437: 0.75//-0.49==-1');
  282.     verify((3/4)//(-1/4)==-3, '438: (3/4)//(-1/4)==-3');
  283.     verify(7%3==1,     '439: 7%3==1');
  284. /* The following is pending a proposed change to allow neg mods
  285.     verify(7%-3==1,    '440: 7%-3==1');
  286.  */
  287.     print '441: Ending test_arithmetic';
  288. }
  289.  
  290.  
  291. /*
  292.  * Test string constants and comparisons
  293.  */
  294. define test_strings()
  295. {
  296.     local x, y, z;
  297.  
  298.     print '500: Beginning test_strings';
  299.     x = 'string';
  300.     y = "string";
  301.     z = x;
  302.     verify(z == "string", '501: z == "string"');
  303.     verify(z != "foo", '502: z != "foo"');
  304.     verify(z != 3, '503: z != 3');
  305.     verify('' == "", '504: \'\' == ""');
  306.     verify("a" == "a", '505: "a" == "a"');
  307.     verify("c" != "d", '506: "c" != "d"');
  308.     verify("" != "a", '507: "" != "a"');
  309.     verify("rs" < "rt", '508: "rs" < "rt"');
  310.     verify("rs" < "ss", '509: "rs < "ss"');
  311.     verify("rs" <= "rs", '510: "rs" <= "rs"');
  312.     verify("rs" <= "tu", '511: "rs" <= "tu"');
  313.     verify("rs" > "cd", '512: "rs" > "cd"');
  314.     verify("rs" >= "rs", '513: "rs" >= "rs"');
  315.     verify("rs" >= "cd", '514: "rs" >= "cd"'); 
  316.     verify("abc" > "ab", '515: "abc" > "ab"');
  317.     print '516: Ending test_strings';
  318. }
  319.  
  320.  
  321. /*
  322.  * Do multiplication and division on three numbers in various ways
  323.  * and verify the results agree.
  324.  */
  325. define muldivcheck(a, b, c, str)
  326. {
  327.     local    abc, acb, bac, bca, cab, cba;
  328.  
  329.     abc = (a * b) * c;
  330.     acb = (a * c) * b;
  331.     bac = (b * a) * c;
  332.     bca = (b * c) * a;
  333.     cab = (c * a) * b;
  334.     cba = (c * b) * a;
  335.  
  336.     if (abc != acb) {print '**** abc != acb:', str; ++err;}
  337.     if (acb != bac) {print '**** acb != bac:', str; ++err;}
  338.     if (bac != bca) {print '**** bac != bca:', str; ++err;}
  339.     if (bca != cab) {print '**** bca != cab:', str; ++err;}
  340.     if (cab != cba) {print '**** cab != cba:', str; ++err;}
  341.     if (abc/a != b*c) {print '**** abc/a != bc:', str; ++err;}
  342.     if (abc/b != a*c) {print '**** abc/b != ac:', str; ++err;}
  343.     if (abc/c != a*b) {print '**** abc/c != ab:', str; ++err;}
  344.     print str;
  345. }
  346.  
  347.  
  348. /*
  349.  * Use the identity for squaring the sum of two squares to check
  350.  * multiplication and squaring.
  351.  */
  352. define squarecheck(a, b, str)
  353. {
  354.     local    a2, b2, tab, apb, apb2, t;
  355.  
  356.     a2 = a^2;
  357.     b2 = b^2;
  358.     tab = a * b * 2;
  359.     apb = a + b;
  360.     apb2 = apb^2;
  361.     if (a2 != a*a) {print '**** a^2 != a*a:', str; ++err;}
  362.     if (b2 != b*b) {print '**** b^2 != b*b:', str; ++err;}
  363.     if (apb2 != apb*apb) {
  364.         print '**** (a+b)^2 != (a+b)*(a+b):', str; 
  365.         ++err;
  366.     }
  367.     if (a2+tab+b2 != apb2) {
  368.         print '**** (a+b)^2 != a^2 + 2ab + b^2:', str; 
  369.         ++err;
  370.     }
  371.     if (a2/a != a) {print '**** a^2/a != a:', str; ++err;}
  372.     if (b2/b != b) {print '**** b^2/b != b:', str; ++err;}
  373.     if (apb2/apb != apb) {print '**** (a+b)^2/(a+b) != a+b:', str; ++err;}
  374.     if (a2*b2 != (a*b)^2) {print '**** a^2*b^2 != (ab)^2:', str; ++err;}
  375.     print str;
  376. }
  377.  
  378.  
  379. /*
  380.  * Use the raising of numbers to large powers to check multiplication
  381.  * and exponentiation.
  382.  */
  383. define powercheck(a, p1, p2, str)
  384. {
  385.     local    a1, a2, a3;
  386.  
  387.     a1 = (a^p1)^p2;
  388.     a2 = (a^p2)^p1;
  389.     a3 = a^(p1*p2);
  390.     if (a1 != a2) {print '**** (a^p1)^p2 != (a^p2)^p1:', str; ++err;}
  391.     if (a1 != a3) {print '**** (a^p1)^p2 != a^(p1*p2):', str; ++err;}
  392.     print str;
  393. }
  394.  
  395.  
  396. /*
  397.  * Test fraction reductions.
  398.  * Arguments MUST be relatively prime.
  399.  */
  400. define fraccheck(a, b, c, str)
  401. {
  402.     local    ab, bc, ca, aoc, boc, aob;
  403.  
  404.     ab = a * b;
  405.     bc = b * c;
  406.     ca = c * a;
  407.     aoc = ab / bc;
  408.     if (num(aoc) != a) {print '**** num(aoc) != a:', str; ++err;}
  409.     if (den(aoc) != c) {print '**** den(aoc) != c:', str; ++err;}
  410.     boc = ab / ca;
  411.     if (num(boc) != b) {print '**** num(boc) != b:', str; ++err;}
  412.     if (den(boc) != c) {print '**** den(boc) != c:', str; ++err;}
  413.     aob = ca / bc;
  414.     if (num(aob) != a) {print '**** num(aob) != a:', str; ++err;}
  415.     if (den(aob) != b) {print '**** den(aob) != b:', str; ++err;}
  416.     if (aob*boc != aoc) {print '**** aob*boc != aoc;', str; ++err;}
  417.     print str;
  418. }
  419.  
  420.  
  421. /*
  422.  * Test multiplication and squaring algorithms.
  423.  */
  424. define algcheck(a, b, str)
  425. {
  426.     local    ss, ms, t1, t2, t3, t4, t5, t6, t7;
  427.     local    a1, a2, a3, a4, a5, a6, a7;
  428.     local    oldmul2, oldsq2;
  429.  
  430.     oldmul2 = config("mul2", 2);
  431.     oldsq2 = config("sq2", 2);
  432.     a1 = a * b;
  433.     a2 = a * a;
  434.     a3 = b * b;
  435.     a4 = a^2;
  436.     a5 = b^2;
  437.     a6 = a2^2;
  438.     a7 = pmod(3,a-1,a);
  439.     for (ms = 2; ms < 20; ms++) {
  440.         for (ss = 2; ss < 20; ss++) {
  441.             config("mul2", ms);
  442.             config("sq2", ss);
  443.             t1 = a * b;
  444.             t2 = a * a;
  445.             t3 = b * b;
  446.             t4 = a^2;
  447.             t5 = b^2;
  448.             t6 = t2^2;
  449.             if (((ms + ss) % 37) == 4)
  450.                 t7 = pmod(3,a-1,a);
  451.             if (t1 != a1) {print '**** t1 != a1:', str; ++err;}
  452.             if (t2 != a2) {print '**** t2 != a2:', str; ++err;}
  453.             if (t3 != a3) {print '**** t3 != a3:', str; ++err;}
  454.             if (t4 != a4) {print '**** t4 != a4:', str; ++err;}
  455.             if (t5 != a5) {print '**** t5 != a5:', str; ++err;}
  456.             if (t6 != a6) {print '**** t6 != a6:', str; ++err;}
  457.             if (t7 != a7) {print '**** t7 != a7:', str; ++err;}
  458.         }
  459.     }
  460.     config("mul2", oldmul2);
  461.     config("sq2", oldsq2);
  462.     print str;
  463. }
  464.  
  465.  
  466. /*
  467.  * Test big numbers using some identities.
  468.  */
  469. define test_bignums()
  470. {
  471.     local    a, b, c, d;
  472.  
  473.     print '600: Beginning test_bignums';
  474.     a = 64357824568234938591;
  475.     b = 12764632632458756817;
  476.     c = 43578234973856347982;
  477.     muldivcheck(a, b, c, '601: muldivcheck 1');
  478.     a = 3^100;
  479.     b = 5^97;
  480.     c = 7^88;
  481.     muldivcheck(a, b, c, '602: muldivcheck 2');
  482.     a = 2^160 - 1;
  483.     b = 2^161 - 1;
  484.     c = 2^162 - 1;
  485.     muldivcheck(a, b, c, '603: muldivcheck 3');
  486.     a = 3^35 / 5^35;
  487.     b = 7^35 / 11^35;
  488.     c = 13^35 / 17^35;
  489.     muldivcheck(a, b, c, '604: muldivcheck 4');
  490.     a = (10^97-1) / 9;
  491.     b = (10^53-1) / 9;
  492.     c = (10^37-1) / 9;
  493.     muldivcheck(a, b, c, '605: muldivcheck 5');
  494.     a = 17^50;
  495.     b = 19^47;
  496.     squarecheck(a, b, '606: squarecheck 1');
  497.     a = 2^111-1;
  498.     b = 2^17;
  499.     squarecheck(a, b, '607: squarecheck 2');
  500.     a = 23^43 / 29^43;
  501.     b = 31^42 / 37^29;
  502.     squarecheck(a, b, '608: squarecheck 3');
  503.     a = 4657892345743659834657238947854639;
  504.     b = 43784356784365893467659347867689;
  505.     squarecheck(a, b, '609: squarecheck 4');
  506.     a = (10^80-1) / 9;
  507.     b = (10^50-1) / 9;
  508.     squarecheck(a, b, '610: squarecheck 5');
  509.     a = 101^99;
  510.     b = 2 * a;
  511.     squarecheck(a, b, '611: squarecheck 6');
  512.     a = (10^19-1) / 9;
  513.     verify(ptest(a, 20), '612: primetest R19');
  514.     a = (10^23-1) / 9;
  515.     verify(ptest(a, 20), '613: primetest R23');
  516.     a = 2^127 - 1;
  517.     verify(ptest(a, 1), '614: primetest M127');
  518.     a = 2^521 - 1;
  519.     verify(ptest(a, 1), '615: primetest M521');
  520.     powercheck(17, 127, 30, '616: powercheck 1');
  521.     powercheck(111, 899, 6, '617: powercheck 2');
  522.     powercheck(3, 87, 89, '618: powercheck 3');
  523.     fraccheck(3^200, 5^173, 7^138, '619: fraccheck 1');
  524.     fraccheck(11^100, 12^98, 13^121, '620: fraccheck 2');
  525.     fraccheck(101^270, 103^111, 105^200, '621: fraccheck 3');
  526.     a = 0xffff0000ffffffff00000000ffff0000000000000000ffff;
  527.     b = 0x555544440000000000000000000000000000000011112222333344440000;
  528.     c = 0x999911113333000011111111000022220000000000000000333300000000ffff;
  529.     d = 0x3333ffffffff0000000000000000ffffffffffffffff000000000000;
  530.     algcheck(a, a, '622: algcheck 1');
  531.     algcheck(a, b, '623: algcheck 2');
  532.     algcheck(a, c, '624: algcheck 3');
  533.     algcheck(a, d, '625: algcheck 4');
  534.     algcheck(b, b, '626: algcheck 5');
  535.     algcheck(b, c, '627: algcheck 6');
  536.     algcheck(b, d, '628: algcheck 7');
  537.     algcheck(c, c, '629: algcheck 8');
  538.     algcheck(c, d, '630: algcheck 9');
  539.     algcheck(d, d, '631: algcheck 10');
  540. /* The following are pending consideration of the 'nearest' arg to sqrt()
  541.     a = 2e150;
  542.     b = 0x3206aa0707c6c1d483b62c784c9371eb507e3ab9b2d511c4bd648e52a5277fe;
  543.     verify(sqrt(a,1) == b, '632: sqrt(a,1) == b');
  544.     verify(sqrt(4e1000,1) == 2e500, '633: sqrt(4e1000,1) == 2e500');
  545.  */
  546.     print '634: Ending test_bignums';
  547. }
  548.  
  549.  
  550. /*
  551.  * Test many of the built-in functions.
  552.  */
  553. define test_functions()
  554. {
  555.     print '700: Beginning test_functions';
  556.     verify(abs(3) == 3,    '701: abs(3) == 3');
  557.     verify(abs(-4) == 4,   '702: abs(-4) == 4');
  558.     verify(avg(7) == 7,    '703: avg(7) == 7');
  559.     verify(avg(3,5) == 4,  '704: avg(3,5) == 4');
  560.     verify(cmp(2,3) == -1, '705: cmp(2,3) == -1');
  561.     verify(cmp(6,6) == 0,  '706: cmp(6,6) == 0');
  562.     verify(cmp(7,4) == 1,  '707: cmp(7,4) == 1');
  563.     verify(comb(9,9) == 1, '708: comb(9,9) == 1');
  564.     verify(comb(5,2) == 10,'709: comb(5,2) == 10');
  565.     verify(conj(4) == 4,   '710: conj(4) == 4');
  566.     verify(conj(2-3i) == 2+3i, '711: conj(2-3i) == 2+3i');
  567.     verify(den(17) == 1,   '712: den(17) == 1');
  568.     verify(den(3/7) == 7,  '713: den(3/7) == 7');
  569.     verify(den(-2/3) == 3, '714: den(-2/3) == 3');
  570.     verify(digits(0) == 1, '715: digits(0) == 1');
  571.     verify(digits(9) == 1, '716: digits(9) == 1');
  572.     verify(digits(10) == 2,'717: digits(10) == 2');
  573.     verify(digits(-691) == 3, '718: digits(-691) == 3');
  574.     verify(eval('2+3') == 5, "719: eval('2+3') == 5");
  575.     verify(fcnt(11,3) == 0,'720: fcnt(11,3) == 0');
  576.     verify(fcnt(18,3) == 2,'721: fcnt(18,3) == 2');
  577.     verify(fib(0) == 0,    '722: fib(0) == 0');
  578.     verify(fib(1) == 1,    '723: fib(1) == 1');
  579.     verify(fib(9) == 34,   '724: fib(9) == 34');
  580.     verify(frem(12,5) == 12, '725: frem(12,5) == 12');
  581.     verify(frem(45,3) == 5, '726: frem(45,3) == 5');
  582.     verify(fact(0) == 1,   '727: fact(0) == 1');
  583.     verify(fact(1) == 1,   '728: fact(1) == 1');
  584.     verify(fact(5) == 120, '729: fact(5) == 120');
  585.     verify(frac(3) == 0,   '730: frac(3) == 0');
  586.     verify(frac(2/3) == 2/3, '731: frac(2/3) == 2/3');
  587.     verify(frac(17/3) == 2/3, '732: frac(17/3) == 2/3');
  588.     verify(gcd(0,3) == 3,  '733: gcd(0,3) == 3');
  589.     verify(gcd(1,12) == 1, '734: gcd(1,12) == 1');
  590.     verify(gcd(11,7) == 1, '735: gcd(11,7) == 1');
  591.     verify(gcd(20,65) == 5, '736: gcd(20,65) == 5');
  592.     verify(gcdrem(20,3) == 20, '737: gcdrem(20,3) == 20');
  593.     verify(gcdrem(100,6) == 25, '738: gcdrem(100,6) == 25');
  594.     verify(highbit(1) == 0, '739: highbit(1) == 0');
  595.     verify(highbit(15) == 3, '740: highbit(15) == 3');
  596.     verify(hypot(3,4) == 5, '741: hypot(3,4) == 5');
  597.     verify(ilog(90,3) == 4, '742: ilog(90,3) == 4');
  598.     verify(ilog10(123) == 2, '743: ilog10(123) == 2');
  599.     verify(ilog2(17) == 4, '744: ilog2(17) == 4');
  600.     verify(im(3) == 0,     '745: im(3) == 0');
  601.     verify(im(2+3i) == 3,  '746: im(2+3i) == 3');
  602.     verify(int(5) == 5,    '757: int(5) == 5');
  603.     verify(int(19/3) == 6, '758: int(19/3) == 6');
  604.     verify(inverse(3/2) == 2/3, '759: inverse(3/2) == 2/3');
  605.     verify(iroot(18,2) == 4, '760: iroot(18,2) == 4');
  606.     verify(iroot(100,3) == 4, '761: iroot(100,3) == 4');
  607.     verify(iseven(10) == 1, '762: iseven(10) == 1');
  608.     verify(iseven(13) == 0, '763: iseven(13) == 0');
  609.     verify(iseven('a') == 0, "764: iseven('a') == 0");
  610.     verify(isint(7) == 1,  '765: isint(7) == 1');
  611.     verify(isint(19/2) == 0, '766: isint(19/2) == 0');
  612.     verify(isint('a') == 0, "767: isint('a') == 0");
  613.     verify(islist(3) == 0, '768: islist(3) == 0');
  614.     verify(islist(list(2,3)) == 1, '769: islist(list(2,3)) == 1');
  615.     verify(ismat(3) == 0, '770: ismat(3) == 0');
  616.     verify(ismult(7,3) == 0, '771: ismult(7,3) == 0');
  617.     verify(ismult(15,5) == 1, '772: ismult(15,5) == 1');
  618.     verify(isnull(3) == 0, '773: isnull(3) == 0');
  619.     verify(isnull(null()) == 1, '774: isnull(null()) == 1');
  620.     verify(isnum(2/3) == 1, '775: isnum(2/3) == 1');
  621.     verify(isnum('xx') == 0, "776: isnum('xx') == 0");
  622.     verify(isobj(3) == 0, '777: isobj(3) == 0');
  623.     verify(isodd(7) == 1, '778: isodd(7) == 1');
  624.     verify(isodd(8) == 0, '779: isodd(8) == 0');
  625.     verify(isodd('x') == 0, "780: isodd('a') == 0");
  626.     verify(isqrt(27) == 5, '781: isqrt(27) == 5');
  627.     verify(isreal(3) == 1, '782: isreal(3) == 1');
  628.     verify(isreal('x') == 0, "783: isreal('x') == 0");
  629.     verify(isreal(2+3i) == 0, '784: isreal(2+3i) == 0');
  630.     verify(isstr(5) == 0,  '785: isstr(5) == 0');
  631.     verify(isstr('foo') == 1, "786: isstr('foo') == 1");
  632.     verify(isrel(10,14) == 0, '787: isrel(10,14) == 0');
  633.     verify(isrel(15,22) == 1, '788: isrel(15,22) == 1');
  634.     verify(issimple(6) == 1, '789: issimple(6) == 1');
  635.     verify(issimple(3-2i) == 1, '790: issimple(3-2i) == 1');
  636.     verify(issimple(list(5)) == 0, '791: issimple(list(5)) == 0');
  637.     verify(issq(26) == 0, '792: issq(26) == 0');
  638.     verify(issq(9/4) == 1, '793: issq(9/4) == 1');
  639.     verify(istype(9,4) == 1, '795: istype(9,4) == 1');
  640.     verify(istype(3,'xx') == 0, "796: istype(3,'xx') == 0");
  641.     verify(jacobi(5,11) == 1, '797: jacobi(2,7) == 1');
  642.     verify(jacobi(6,13) == -1, '798: jacobi(6,13) == 0');
  643.     verify(lcm(3,4,5,6) == 60, '799: lcm(3,4,5,6) == 60');
  644.     verify(lcmfact(8) == 840, '800: lcmfact(8) == 840');
  645.     verify(lfactor(21,5) == 3, '801: lfactor(21,5) == 3');
  646.     verify(lfactor(97,20) == 1, '802: lfactor(97,20) == 1');
  647.     verify(lowbit(12) == 2, '803: lowbit(12) == 2');
  648.     verify(lowbit(17) == 0, '804: lowbit(17) == 0');
  649.     verify(ltol(1) == 0, '805: ltol(1) == 0');
  650.     verify(max(3,-9,7,4) == 7, '806: max(3,-9,7,4) == 7');
  651.     verify(meq(13,33,10) == 1, '807: meq(13,33,10) == 1');
  652.     verify(meq(7,19,11) == 0, '808: meq(7,19,11) == 0');
  653.     verify(min(9,5,12) == 5, '809: min(9,5,12) == 5');
  654.     verify(minv(13,97) == 15, '810: minv(13,97) == 15');
  655.     verify(mne(16,37,10) == 1, '811: mne(16,37,10) == 1');
  656.     verify(mne(46,79,11) == 0, '812: mne(46,79,11) == 0');
  657.     verify(norm(4) == 16,   '813: norm(4) == 16');
  658.     verify(norm(2-3i) == 13, '814: norm(2-3i) == 13');
  659.     verify(num(7) == 7,     '815: num(7) == 7');
  660.     verify(num(11/4) == 11, '816: num(11/4) == 11');
  661.     verify(num(-9/5) == -9, '817: num(-9/5) == -9');
  662.     verify(char(ord('a')+2) == 'c', "818: char(ord('a')+2) == 'c'");
  663.     verify(perm(7,3) == 210, '819: perm(7,3) == 210');
  664.     verify(pfact(10) == 210, '820: pfact(10) == 210');
  665.     verify(places(3/7) == -1, '821: places(3/7) == -1');
  666.     verify(places(.347) == 3, '822: places(.347) == 3');
  667.     verify(places(17) == 0, '823: places(17) == 0');
  668.     verify(pmod(3,36,37) == 1, '824: pmod(3,36,37) == 1');
  669.     verify(poly(2,3,5,2) == 19, '825; poly(2,3,5,2) == 19');
  670.     verify(ptest(101,10) == 1, '826: ptest(101,10) == 1');
  671.     verify(ptest(221,30) == 0, '827: ptest(221,30) == 0');
  672.     verify(re(9) == 9,       '828: re(9) == 9');
  673.     verify(re(-7+3i) == -7,  '829: re(-7+3i) == -7');
  674.     verify(scale(3,4) == 48, '830: scale(3,4) == 48');
  675.     verify(sgn(-4) == -1,    '831: sgn(-4) == -1');
  676.     verify(sgn(0) == 0,      '832: sgn(0) == 0');
  677.     verify(sgn(3) == 1,      '833: sgn(3) == 1');
  678.     verify(size(7) == 1,     '834: size(7) == 1');
  679.     verify(sqrt(121) == 11,  '835: sqrt(121) == 11');
  680.     verify(ssq(2,3,4) == 29, '836: ssq(2,3,4) == 29');
  681.     verify(str(45) == '45',  "837; str(45) == '45'");
  682.     verify(strcat('a','bc','def')=='abcdef',"838; strcat('a','bc','def')=='abcdef'");
  683.     verify(strlen('') == 0,  "839: strlen('') == 0");
  684.     verify(strlen('abcd') == 4, "840: strlen('abcd') == 4");
  685.     verify(substr('abcd',2,1) == 'b', "841: substr('abcd',2,1) == 'b'");
  686.     verify(substr('abcd',3,4) == 'cd', "842: substr('abcd',3,4) == 'cd'");
  687.     verify(substr('abcd',1,3) == 'abc', "843: substr('abcd',1,3) == 'abc'");
  688.     verify(xor(17,17) == 0,  '844: xor(17,17) == 0');
  689.     verify(xor(12,5) == 9,   '845: xor(12,5) == 9');
  690.     verify(mmin(3,7) == 3, '846: mmin(3,7) == 3');
  691.     verify(mmin(4,7) == -3, '847: mmin(4,7) == -3');
  692.     verify(digit(123,2) == 1, '848: digit(123,2) == 1');
  693.     verify(ismult(3/4, 1/7) == 0, '849: ismult(3/4, 1/7) == 0');
  694.     verify(gcd(3/4, 1/7) == 1/28, '850: gcd(3/4,1/7) == 1/28');
  695. /* The following are pending consideration of the 'nearest' arg to sqrt()
  696.     verify(sqrt(122,1) == 11,  '851: sqrt(122,1) == 11');
  697.     verify(sqrt(110,1) == 10,  '852: sqrt(110,1) == 10');
  698.     verify(sqrt(110,0.1) == 10.5,  '853: sqrt(110,0.1) == 10.5');
  699.     verify(sqrt(115,0.1) == 10.75,  '854: sqrt(115,0.1) == 10.75');
  700.  */
  701.     print '855: Ending test_functions';
  702. }
  703.  
  704.  
  705. /*
  706.  * Report the number of errors found.
  707.  */
  708. define count_errors()
  709. {
  710.     if (err == 0) {
  711.         print "999: passed all tests  /\\../\\";
  712.     } else {
  713.         print "****", err, "error(s) found  \\/++\\/";
  714.     }
  715. }
  716.  
  717.  
  718. print '001: Beginning regression tests';
  719. print '002: Within each section, output should be numbered sequentially';
  720. print;
  721. return test_booleans();
  722. print;
  723. return test_variables();
  724. print;
  725. return test_logicals();
  726. print;
  727. return test_arithmetic();
  728. print;
  729. return test_strings();
  730. print;
  731. return test_bignums();
  732. print;
  733. return test_functions();
  734. print;
  735. return count_errors();
  736.